//
//  WithdrawController.m
//  TCProject
//
//  Created by admin on 16/2/1.
//  Copyright © 2016年 wise-wing. All rights reserved.
//

#import "WithdrawController.h"
#import "AccountManager.h"
#import "CZIncomeController.h"

@interface WithdrawController ()

@property (weak, nonatomic) IBOutlet UILabel *h1;
@property (weak, nonatomic) IBOutlet UITextField *priceTextField;
- (IBAction)commitAction:(id)sender;

@end

@implementation WithdrawController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.h1.text = [NSString stringWithFormat:@"本次最多可提现%.2f", _price];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)commitAction:(id)sender {
    double p = [self.priceTextField.text doubleValue];
    if (p <= 0 || p > _price) {
        [self showHint:@"请输入正确金额"];
        return;
    }
    BMRequest *request = [BMRequest requestWithPath:@"getMoney.htm"];
    request.params = @{@"id": @([AccountManager sharedInstance].user.ID), @"money": @(p)};
    [self showHudWithhint:kDefaultMessage];
    [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"提现成功" preferredStyle:UIAlertControllerStyleAlert];
            [alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSArray *vcs = self.navigationController.childViewControllers;
                CZIncomeController *vc = vcs[vcs.count - 2];
                [vc refreshData];
                [self.navigationController popViewControllerAnimated:YES];
            }]];
            [self presentViewController:alertVC animated:YES completion:nil];
        } else {
            [self showHint:@"提现失败"];
        }
    }];

}
@end
